package com.example.project3;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ProfileEditActivity extends AppCompatActivity {

    private static final int REQUEST_INTEREST = 1;
    private TextView tvUsername, tvInterest;
    private Button btnBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile_edit_activity);

        btnBack = findViewById(R.id.btn_back);
        tvUsername = findViewById(R.id.tv_username);
        tvInterest = findViewById(R.id.tv_interest);

        // 接收并显示用户名
        String username = getIntent().getStringExtra("username");
        tvUsername.setText("用户名：" + username);

        // 返回按钮（点击颜色变深为系统默认反馈）
        btnBack.setOnClickListener(v -> finish());

        // 点击兴趣文本框跳转到兴趣选择页
        tvInterest.setOnClickListener(v -> {
            Intent intent = new Intent(ProfileEditActivity.this, InterestSelectActivity.class);
            startActivityForResult(intent, REQUEST_INTEREST);
        });
    }

    // 接收兴趣选择页回传数据
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_INTEREST && resultCode == RESULT_OK && data != null) {
            String interest = data.getStringExtra("interest");
            tvInterest.setText("兴趣：" + interest);
        }
    }
}